use "E:\隨身硬碟備份\E\TRY\findev_2017\Fin_Co2_pol_2020\program\n82_4y_8417_renew.dta",clear
set more off 
mata: mata set matafavor speed, perm
tsset id period

egen free_a=mean(sc_right),   by(id)
egen fd_a=  mean(fin_dev),    by(id)
egen fs_a=  mean(fin_str),    by(id)
egen bon_a= mean(av_bon),     by(id)
egen ler_a= mean(av_lern),    by(id)
egen con_a= mean(lnav_concn), by(id)
egen hh_a=  mean(lnav_borhh), by(id)
egen fm_a=  mean(lnav_borfm), by(id)

tabstat free_a fd_a fs_a bon_a ler_a con_a hh_a fm_a, ///
stat(min p10 p25 p50 mean p75 p90 max)

**aggregate**

gen fd1_y=0 if id==76
replace fd1_y=0 if id==69
replace fd1_y=0 if id==31
replace fd1_y=-0.0112 if id==13
replace fd1_y=0.0630  if id==80
gen fd_1=0.06098 if id==76
replace fd_1=0.1571 if id==69
replace fd_1=0.2189 if id==31
replace fd_1=0.0038 if id==13
replace fd_1=1 if id==80

gen fs1_y=0 if id==12
replace fs1_y=0 if id==28
replace fs1_y=0.0255 if id==13
replace fs1_y=-0.0083 if id==80
gen fs_1=0.6314 if id==12
replace fs_1=0.7630 if id==28
replace fs_1=0.0038 if id==13
replace fs_1=1 if id==80

xtabond2 lnav_techpc c.fin_dev c.fin_dev#c.sc_right c.fin_str c.fin_str#c.sc_right c.sc_right ///
c.lnav_gdp c.lnav_gdp#c.lnav_gdp ln_techpc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0, ///
gmm(c.fin_dev, lag(2 4)orthogonal)     gmm(c.fin_dev#c.sc_right, lag(1 1)collapse ) ///
gmm(c.fin_str, lag(2 2))               gmm(c.fin_str#c.sc_right, lag(1 1)collapse ) ///
gmm(c.sc_right,lag(2 2) collapse) ///
gmm(c.lnav_gdp,lag(1 1)orthogonal)     gmm(c.lnav_gdp#c.lnav_gdp,lag(1 1)orthogonal) ///  
iv(ln_techpc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0) ///
twostep small
margins, dydx(c.lnav_gdp)
sum fin_dev fin_str sc_right lnav_gdp

/*FD
找x軸的轉折點
margins, dydx(c.fin_dev) at(sc_right=(0.06013 (0.00001) 0.06015))
margins, dydx(c.fin_dev) at(sc_right=(0.2189  (0.00001) 0.2191))
找不同分位下的邊際效果
margins, dydx(c.fin_dev) at(sc_right=0.0038)
margins, dydx(c.fin_dev) at(sc_right=0.0561)
margins, dydx(c.fin_dev) at(sc_right=0.1666)
margins, dydx(c.fin_dev) at(sc_right=0.4366)
margins, dydx(c.fin_dev) at(sc_right=0.9444)
margins, dydx(c.fin_dev) at(sc_right=1)
margins, dydx(c.fin_dev) at(sc_right=0.5076)
*/


margins, dydx(c.fin_dev) at(sc_right=(0.0038 (0.02) 1.02))             
marginsplot, recast(line) recastci(rline)  ///
title("(c) Effect of findev on green technology") ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5076, lcolor(red) lpattern(dash)) ///
ytitle("∂ green technology / ∂ findev") ///
ylabel(#4) ylabel(, format(%3.2f) angle(0)) ///
ymlabel(-0.0112 0.0263 0.0630, format(%4.3f) labcolor(black) angle(0)) ///
xtitle("free", margin(top)) ///
xmlabel(0.0038 0.5076 0.0601 0.1532 0.2189 1, format(%3.2f) labcolor(black)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))  ///
addplot(scatter fd1_y fd_1, msymbol(O) msize(vsmall) mcolor(black)) ///
text (-0.0112 0.0038  "CHN", place(se) size(small)) ///
text (0.0263  0.5076       , place(nw) size(small)) ///
text (0 0.0601       , place(nw) size(small)) ///
text (0 0.0561  "UGA", place(nw) size(small)) ///
text (0 0.1532       , place(se) size(small)) ///
text (0 0.1571  "LKA", place(se) size(small)) ///
text (0 0.2189  "IDN", place(se) size(small)) ///
text (0.0630 1  "USA", place(n)  size(small))

/*FS
找x軸的轉折點
margins, dydx(c.fin_str) at(sc_right=(0.6313 (0.00001) 0.6316))
找不同分位下的邊際效果
margins, dydx(c.fin_str) at(sc_right=0.0038)
margins, dydx(c.fin_str) at(sc_right=0.0561)
margins, dydx(c.fin_str) at(sc_right=0.1666)
margins, dydx(c.fin_str) at(sc_right=0.4366)
margins, dydx(c.fin_str) at(sc_right=0.9444)
margins, dydx(c.fin_str) at(sc_right=1)
margins, dydx(c.fin_str) at(sc_right=0.075)
*/

margins, dydx(c.fin_str) at(sc_right=(0.0038 (0.02) 1.02))             
marginsplot, recast(line) recastci(rline)  ///
title("(f) Effect of finstr on green technology") ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5076, lcolor(red) lpattern(dash)) ///
ytitle("∂ green technology / ∂ finstr") ///
ylabel(#4) ylabel(, format(%3.2f) angle(0)) ///
ymlabel(0.0255 0.0084 -0.0083, format(%4.3f) labcolor(black) angle(0)) ///
xtitle("free", margin(top)) ///
xmlabel(0.0255 0.5076 0.6314 0.7581 1, format(%3.2f) labcolor(black)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))  ///
addplot(scatter fs1_y fs_1, msymbol(O) msize(vsmall) mcolor(black)) ///
text (0.0255  0.0038  "CHN", place(ne) size(small)) ///
text (0.0084  0.5076       , place(ne) size(small)) ///
text (0 0.6314       , place(sw) size(small)) ///
text (0 0.6098  "CHL", place(sw) size(small)) ///
text (0 0.7581       , place(sw) size(small)) ///
text (0 0.7630  "GRC", place(sw) size(small)) ///
text (-0.0083 1 "USA", place(s)  size(small))


**boone**
gen bon1_y=0 if id==57
replace bon1_y=0 if id==30
replace bon1_y=0 if id==27
replace bon1_y=-0.1238 if id==13
replace bon1_y=0.2019  if id==80
gen bon_1=0.1666 if id==57
replace bon_1=0.3792 if id==30
replace bon_1=0.5014 if id==27
replace bon_1=0.0038  if id==13
replace bon_1=1 if id==80


xtabond2 lnav_techpc c.fin_dev c.fin_dev#c.sc_right c.av_bon c.av_bon#c.sc_right c.sc_right ///
c.lnav_gdp c.lnav_gdp#c.lnav_gdp ln_techpc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0, ///
gmm(c.fin_dev,    lag(1 1)orthogonal)    gmm(c.fin_dev#c.sc_right, lag(1 1)orthogonal) ///
gmm(c.av_bon,     lag(3 3))              gmm(c.av_bon#c.sc_right,  lag(1 2)collapse) ///
gmm(c.sc_right,   lag(2 2)collapse) ///
gmm(c.lnav_gdp,   lag(2 4))              gmm(c.lnav_gdp#c.lnav_gdp,lag(2 4) ) ///  
iv(ln_techpc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0)  ///
twostep small


/*Boone
找x軸的轉折點
margins, dydx(c.av_bon) at(sc_right=(0.16527 (0.00001) 0.16530))
margins, dydx(c.av_bon) at(sc_right=(0.5050  (0.00001) 0.50502))
找不同分位下的邊際效果
margins, dydx(c.av_bon) at(sc_right=0.0038)
margins, dydx(c.av_bon) at(sc_right=0.0561)
margins, dydx(c.av_bon) at(sc_right=0.1666)
margins, dydx(c.av_bon) at(sc_right=0.4366)
margins, dydx(c.av_bon) at(sc_right=0.9444)
margins, dydx(c.av_bon) at(sc_right=1)
margins, dydx(c.av_bon) at(sc_right=0.5076)
*/

margins, dydx(c.av_bon) at(sc_right=(0.0038 (0.02) 1.02))             
marginsplot, recast(line) recastci(rline)  ///
title("(c) Effect of Boone on green technology") ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5076, lcolor(red) lpattern(dash)) ///
ytitle("∂ green technology / ∂ Boone") ///
ylabel(#4) ylabel(, format(%3.2f) angle(0)) ///
ymlabel(-0.1238 0.0409 0.2019, format(%4.3f) labcolor(black) angle(0)) ///
xtitle("free", margin(top)) ///
xmlabel(0.0038 0.1653 0.3827 0.5050 0.5075 1, format(%3.2f) labcolor(black)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))  ///
addplot(scatter bon1_y bon_1, msymbol(O) msize(vsmall) mcolor(black)) ///
text (-0.1238  0.0038  "CHN", place(se) size(small)) ///
text (0.0409   0.5075       , place(se) size(small)) ///
text (0 0.1653       , place(nw) size(small)) ///
text (0 0.1666  "PRY", place(nw) size(small)) ///
text (0 0.3827       , place(se) size(small)) ///
text (0 0.3792  "IND", place(se) size(small)) ///
text (0 0.5050       , place(se) size(small)) ///
text (0 0.5014  "GHA", place(se) size(small)) ///
text (0.2019  1 "USA", place(n)  size(small))

/*
margins, dydx(c.fin_dev) at(sc_right=0.5024428)                                             
margins, dydx(c.fin_dev) at(sc_right=(0 (0.03) 1))             
marginsplot, recast(line) recastci(rline) ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5024428, lcolor(red) lpattern(dash)) ///
ytitle("∂ green technology / ∂ findev") ///
xtitle("free", margin(top)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))
*/

**concerntration**
gen concn1_y=0 if id==41
replace concn1_y=0 if id==29
replace concn1_y=0 if id==26
replace concn1_y=-0.1890 if id==13
replace concn1_y=0.0893 if id==80
gen concn_1=0.5570 if id==41
replace concn_1=0.6729 if id==29
replace concn_1=0.8277 if id==26
replace concn_1=0.0038 if id==13
replace concn_1=1 if id==80

xtabond2 lnav_techpc c.fin_dev c.fin_dev#c.sc_right c.lnav_concn c.lnav_concn#c.sc_right c.sc_right ///
c.lnav_gdp c.lnav_gdp#c.lnav_gdp ln_techpc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0, ///
gmm(c.fin_dev,    lag(1 1) collapse)    gmm(c.fin_dev#c.sc_right,    lag(1 2) ) ///
gmm(c.lnav_concn, lag(2 2) )            gmm(c.lnav_concn#c.sc_right, lag(1 3) collapse) ///
gmm(c.sc_right,   lag(1 1) collapse) ///
gmm(c.lnav_gdp,   lag(1 2) )    gmm(c.lnav_gdp#c.lnav_gdp,  lag(1 2) ) ///  
iv(ln_techpc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0) ///
twostep small

/*
concerntration找x軸的轉折點
margins, dydx(c.lnav_concn) at(sc_right=(0.57564 (0.00001) 0.57566))
margins, dydx(c.lnav_concn) at(sc_right=(0.81852 (0.00001) 0.81854))
找不同分位下的邊際效果
margins, dydx(c.lnav_concn) at(sc_right=0.0038)
margins, dydx(c.lnav_concn) at(sc_right=0.0561)
margins, dydx(c.lnav_concn) at(sc_right=0.1666)
margins, dydx(c.lnav_concn) at(sc_right=0.4366)
margins, dydx(c.lnav_concn) at(sc_right=0.9444)
margins, dydx(c.lnav_concn) at(sc_right=1)
margins, dydx(c.lnav_concn) at(sc_right=0.5076)
*/

margins, dydx(lnav_concn) at(sc_right=(0.0038 (0.02) 1.02))             
marginsplot, recast(line) recastci(rline)  ///
title("(f) Effect of concerntration on green technology") ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5076, lcolor(red) lpattern(dash)) ///
ytitle("∂ green technology / ∂ concerntration") ///
ylabel(#4) ylabel(, format(%3.2f) angle(0)) ///
ymlabel(-0.1890 -0.0482 0.0893, format(%4.3f) labcolor(black) angle(0)) ///
xtitle("free", margin(top)) ///
xmlabel(0.0038 0.5076 0.5757 0.6800 0.8185 1, format(%3.2f) labcolor(black)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))  ///
addplot(scatter concn1_y concn_1, msymbol(O) msize(vsmall) mcolor(black)) ///
text (-0.1890  0.0038  "CHN", place(se) size(small)) ///
text (-0.0482  0.5076       , place(nw) size(small)) ///
text (0 0.5757       , place(nw) size(small)) ///
text (0 0.5570  "LVA", place(nw) size(small)) ///
text (0 0.6800       , place(nw) size(small)) ///
text (0 0.6729  "HUN", place(nw) size(small)) ///
text (0 0.8185       , place(nw) size(small)) ///
text (0 0.8277  "DEU", place(nw) size(small)) ///
text (0.0893  1 "USA", place(n)  size(small))

use "E:\隨身硬碟備份\E\TRY\findev_2017\Fin_Co2_pol_2018\dynamic gmm_4y\n82_4y_fin_202005.dta",clear
set more off
tsset id period
egen free_a=mean(sc_right),   by(id)
egen hh_a=  mean(lnav_borhh), by(id)
egen fm_a=  mean(lnav_borfm), by(id)

tabstat free_a hh_a fm_a, ///
stat(min p10 p25 p50 mean p75 p90 max)

*credit composition*

gen hh1_y=0 if id==64
replace hh1_y=0 if id==31
replace hh1_y=0 if id==20
replace hh1_y=-0.0310 if id==13
replace hh1_y=0.1093 if id==80
gen hh_1=0.1445 if id==64
replace hh_1=0.2236 if id==31
replace hh_1=0.3014 if id==20
replace hh_1=0.0038 if id==13
replace hh_1=1 if id==80

gen fm1_y=0 if id==56
replace fm1_y=0 if id==26
replace fm1_y=0.0686 if id==13
replace fm1_y=-0.0164 if id==80
gen fm_1=0.5354 if id==56
replace fm_1=0.8277 if id==26
replace fm_1=0.0038 if id==13
replace fm_1=1 if id==80

xtabond2 lnav_techpc c.lnav_borhh c.lnav_borhh#c.sc_right c.lnav_borfm c.lnav_borfm#c.sc_right c.sc_right ///
c.lnav_gdp c.lnav_gdp#c.lnav_gdp ln_techpc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0, ///
gmm(c.lnav_borhh, lag(2 2) orthogonal)      gmm(c.lnav_borhh#c.sc_right, lag(1 2) orthogonal) ///
gmm(c.lnav_borfm, lag(2 2) )                gmm(c.lnav_borfm#c.sc_right, lag(2 2) collapse ) ///
gmm(c.sc_right,   lag(1 1) collapse) ///
gmm(c.lnav_gdp,   lag(1 2)   )   gmm(c.lnav_gdp#c.lnav_gdp,   lag(1 1) ) ///  
iv(ln_techpc0 ln_trad0 ln_urb0 ln_sec0 ln_inds0) ///
twostep small

/*household credit
找x軸的轉折點
margins, dydx(c.lnav_borhh) at(sc_right=(0.13856 (0.00001) 0.13858))
margins, dydx(c.lnav_borhh) at(sc_right=(0.29590 (0.00001) 0.29591))
找不同分位下的邊際效果
margins, dydx(c.lnav_borhh) at(sc_right=0.0038)
margins, dydx(c.lnav_borhh) at(sc_right=0.0561)
margins, dydx(c.lnav_borhh) at(sc_right=0.1666)
margins, dydx(c.lnav_borhh) at(sc_right=0.4366)
margins, dydx(c.lnav_borhh) at(sc_right=0.9444)
margins, dydx(c.lnav_borhh) at(sc_right=1)
margins, dydx(c.lnav_borhh) at(sc_right=0.5076)
*/


margins, dydx(lnav_borhh) at(sc_right=(0.0038 (0.02) 1.02))             
marginsplot, recast(line) recastci(rline)  ///
title("(c) Effect of household credit on green technology") ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5076, lcolor(red) lpattern(dash)) ///
ytitle("∂ green technology / ∂ household credit") ///
ylabel(#4) ylabel(, format(%3.2f) angle(0)) ///
ymlabel(-0.0310 0.0400 0.1093, format(%4.3f) labcolor(black) angle(0)) ///
xtitle("free", margin(top)) ///
xmlabel(0.0038 0.5076 0.1386 0.2239 0.2959 1, format(%3.2f) labcolor(black)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))  ///
addplot(scatter hh1_y hh_1, msymbol(O) msize(vsmall) mcolor(black)) ///
text (-0.0310  0.0038  "CHN", place(se) size(small)) ///
text (0.0400   0.5076       , place(nw) size(small)) ///
text (0 0.1386       , place(nw) size(small)) ///
text (0 0.1445  "RUS", place(nw) size(small)) ///
text (0 0.2239       , place(nw) size(small)) ///
text (0 0.2236  "IDN", place(nw) size(small)) ///
text (0 0.2959       , place(se) size(small)) ///
text (0 0.3014  "ECU", place(se) size(small)) ///
text (0.1093 1  "USA", place(n)  size(small))

/*enterprise credit
找x軸的轉折點
margins, dydx(c.lnav_borfm) at(sc_right=(0.54766 (0.00001) 0.54767))
找不同分位下的邊際效果
margins, dydx(c.lnav_borfm) at(sc_right=0.0038)
margins, dydx(c.lnav_borfm) at(sc_right=0.0561)
margins, dydx(c.lnav_borfm) at(sc_right=0.1666)
margins, dydx(c.lnav_borfm) at(sc_right=0.4366)
margins, dydx(c.lnav_borfm) at(sc_right=0.9444)
margins, dydx(c.lnav_borfm) at(sc_right=1)
margins, dydx(c.lnav_borfm) at(sc_right=0.5076)
*/

margins, dydx(lnav_borfm) at(sc_right=(0.0038 (0.02) 1.02))             
marginsplot, recast(line) recastci(rline)  ///
title("(f) Effect of enterprise credit on green technology") ///
yline(0, lcolor(green) lpattern(dash)) ///
xline(0.5076, lcolor(red) lpattern(dash)) ///
ytitle("∂ green technology / ∂ enterprise credit") ///
ylabel(#4) ylabel(, format(%3.2f) angle(0)) ///
ymlabel(0.0686 0.0256 -0.0164, format(%4.3f) labcolor(black) angle(0)) ///
xtitle("free", margin(top)) ///
xmlabel(0.0042 0.5076 0.5477 0.8077 1, format(%3.2f) labcolor(black)) ///
ciopts(lpattern(dot) lcolor(gray) lwidth(medthick))  ///
addplot(scatter fm1_y fm_1, msymbol(O) msize(vsmall) mcolor(black)) ///
text (0.0686  0.0038  "CHN", place(ne) size(small)) ///
text (0.0256  0.5076       , place(ne) size(small)) ///
text (0 0.5477       , place(ne) size(small)) ///
text (0 0.5354  "PAN", place(ne) size(small)) ///
text (0 0.8077       , place(ne) size(small)) ///
text (0 0.8277  "DEU", place(ne) size(small)) ///
text (-0.0164 1 "USA", place(s)  size(small))



